import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';
import { ConfigService } from './config.service';
import { Carousel } from '../model/carousel';

@Injectable()
export class CarouselService {

  constructor(
    private http:HttpClient,
    private config:ConfigService
  ) { }

  private  getCarouselListUrl=this.config.host+"/manage/getCarouselList";
getCarouselList(){

  return this.http.get(this.getCarouselListUrl).toPromise();
}

addCarouselUrl=this.config.host+"/manage/addCarousel";
addCarousel(carousel:Carousel){
let p={
  "carouselid":carousel.carouselid,
  "pic":carousel.pic,
  "title":carousel.title,
  "discription":carousel.discription,
  "content":carousel.content
}
return this.http.post(this.addCarouselUrl,p).toPromise();
}

private deleteCarouselUrl=this.config.host+"/manage/deleteCarousel";
deleteCarousel(id:string){
  let p={
    "carouselid":id
  }
  return this.http.post(this.deleteCarouselUrl,p).toPromise();
}

private getCarouselUrl=this.config.host+"/manage/getCarousel";

getCarousel(id:string){
  let p={
    "carouselid":id
  }
  return this.http.post(this.getCarouselUrl,p).toPromise();
}

private updateCarouselUrl=this.config.host+"/manage/updateCarousel";

updateNews(carousel:Carousel){
  let p={
      "carouselid":carousel.carouselid,
      "pic":carousel.pic,
      "title":carousel.title,
      "discription":carousel.discription,
      "content":carousel.content
  }
  return this.http.post(this.updateCarouselUrl,p).toPromise();
}
}
